<%@taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions"%>

<h2><fmt:message key = "requestListForm.title"/></h2>

<div class = "messages"><jsp:include page = "/messages.jsp"/></div>

<div class="links">
<ul class = "navbar2">
   <li>
      <a class = "control" href = "chiefui?_action=requestAddForm">
         <fmt:message key = "Command.add"/>
      </a>      
   </li>
</ul>
</div>

   <table class = "regular">
      <thead>
         <tr>                                                     
            <th width="50"><a class="head" href="chiefui?_action=listRequests&orderBy=N&order=${order}&page=${currentPage}">N</a></th>            
            <th width="50"><a class="head" href="chiefui?_action=listRequests&orderBy=regnumber&order=${order}&page=${currentPage}"><fmt:message key = "request.regNumber"/></a></th>            
            <th width="120"><a class="head" href="chiefui?_action=listRequests&orderBy=client&order=${order}&page=${currentPage}"><fmt:message key = "request.client"/></a></th>
            <th width="120"><a class="head" href="chiefui?_action=listRequests&orderBy=organization&order=${order}&page=${currentPage}"><fmt:message key = "request.organization"/></a></th>            
            <th><fmt:message key = "request.text"/></th>
            <th width="80"><a class="head" href="chiefui?_action=listRequests&orderBy=state&order=${order}&page=${currentPage}"><fmt:message key = "request.status"/></a></th>
            <th width="80"><fmt:message key = "request.operations"/></th>
         </tr>
      </thead>

      <tbody>
      	<c:choose>
        <c:when test="${fn:length(requestsList) != 0}">
         <c:forEach var = "request" items = "${requestsList}">
           <c:choose>
             <c:when test='${request.requestStatus.id == 1}'>
               <tr class = "newRequest">
             </c:when>
             <c:otherwise>
               <tr>
             </c:otherwise>     
           </c:choose>
               <td><c:out value="${request.id}"/></td>
               <td><c:out value="${request.regNumber}"/></td> 
               <td><c:out value="${request.client.formName}"/></td>
               <td><c:out value="${request.organization.shortTitle}"/></td>                                          
               <td class="textField">
                  <c:choose>
                  <c:when test='${request.dispatcherText == null}'>
                    <c:out value="${fn:substring(request.clientText, 0, 200)}"/>
                  </c:when>
                  <c:otherwise>
                    <c:out value="${fn:substring(request.dispatcherText, 0, 200)}"/>
                  </c:otherwise>
               </c:choose>
               </td>
               <td><c:out value="${request.requestStatus.status}"/></td>
               <td>
                 <ul class = "navbar2"> 
                     <li>
                       <a class = "control" href = 'chiefui?_action=requestDetails&request_id=${request.id}'>
                         <fmt:message key = "request.operations.view"/>
                       </a>
                     </li>                                    
                 </ul>
               </td>
            </tr>
         </c:forEach>
         </c:when>
<c:otherwise>
<tr><td colspan = "7"><center><fmt:message key="emptyList"/></center></td></tr>
</c:otherwise>     
</c:choose>
      </tbody>
   </table>
   
<p><jsp:include page = "/pageNavigation.jsp"/></p>

<div class = "links">
<ul class = "navbar2">
   <li>
      <a class = "control" href = "chiefui?_action=requestAddForm">
         <fmt:message key = "Command.add"/>
      </a>      
   </li>
</ul>
</div>